<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:espace="espace:StringHelper">
<xsl:output method="text" />
<xsl:template match="/">using System;
using System.Data;
using <xsl:value-of select="Schema/@EntityNameSpace" />;
using <xsl:value-of select="Schema/@DataAccessNameSpace" />;

namespace <xsl:value-of select="Schema/@NameSpace" />
{
	public class <xsl:value-of select="Schema/@TableName" />Biz
	{
		public <xsl:if test="Schema/@IsStatic='True'">static </xsl:if>void Add<xsl:value-of select="Schema/@TableName" />(<xsl:value-of select="concat(Schema/@TableName, ' ', espace:PascalToCamel(Schema/@TableName))" />)
		{
			_<xsl:value-of select="Schema/@TableName" />Insert <xsl:value-of select="espace:PascalToCamel(Schema/@TableName)" />Insert = new _<xsl:value-of select="Schema/@TableName" />Insert();
			<xsl:value-of select="espace:PascalToCamel(Schema/@TableName)" />Insert.ReceiveParameter(<xsl:value-of select="espace:PascalToCamel(Schema/@TableName)" />);
			<xsl:value-of select="espace:PascalToCamel(Schema/@TableName)" />Insert.ExecuteNonQuery();
			<xsl:for-each select="Schema/Columns[IsIdentity='true']">
			<xsl:value-of select="espace:PascalToCamel(/Schema/@TableName)" />.<xsl:value-of select="ColumnName" /> = <xsl:value-of select="espace:PascalToCamel(/Schema/@TableName)" />Insert.<xsl:value-of select="ColumnName" />;</xsl:for-each>
		}

		public <xsl:if test="Schema/@IsStatic='True'">static </xsl:if>DataTable GetAll<xsl:value-of select="Schema/@TableName" />()
		{
			_<xsl:value-of select="Schema/@TableName" />SelectAll <xsl:value-of select="espace:PascalToCamel(Schema/@TableName)" />SelectAll = new _<xsl:value-of select="Schema/@TableName" />SelectAll();
			return <xsl:value-of select="espace:PascalToCamel(Schema/@TableName)" />SelectAll.ExecuteDataTable();
		}<xsl:if test="Schema/@IfHavePK=1 and Schema/@IfAllPK=0">

		public <xsl:if test="Schema/@IsStatic='True'">static </xsl:if>void Update<xsl:value-of select="Schema/@TableName" />(<xsl:value-of select="concat(Schema/@TableName, ' ', espace:PascalToCamel(Schema/@TableName))" />)
		{
			_<xsl:value-of select="Schema/@TableName" />Update <xsl:value-of select="espace:PascalToCamel(Schema/@TableName)" />Update = new _<xsl:value-of select="Schema/@TableName" />Update();
			<xsl:value-of select="espace:PascalToCamel(Schema/@TableName)" />Update.ReceiveParameter(<xsl:value-of select="espace:PascalToCamel(Schema/@TableName)" />);
			<xsl:value-of select="espace:PascalToCamel(Schema/@TableName)" />Update.ExecuteNonQuery();
		}</xsl:if><xsl:if test="Schema/@IfHavePK=1">

		public <xsl:if test="Schema/@IsStatic='True'">static </xsl:if>void Delete<xsl:value-of select="Schema/@TableName" />(<xsl:for-each select="Schema/Columns[IsPK='1']"><xsl:value-of select="concat(LanguageType,' ',espace:PascalToCamel(ColumnName))" /><xsl:if test="position()!=last()">,</xsl:if></xsl:for-each>)
		{
			_<xsl:value-of select="Schema/@TableName" />Delete <xsl:value-of select="espace:PascalToCamel(Schema/@TableName)" />Delete = new _<xsl:value-of select="Schema/@TableName" />Delete();
			<xsl:for-each select="Schema/Columns[IsPK='1']">
			<xsl:value-of select="espace:PascalToCamel(/Schema/@TableName)" />Delete.<xsl:value-of select="ColumnName" /> = <xsl:value-of select="espace:PascalToCamel(ColumnName)" />;
			</xsl:for-each>
			<xsl:value-of select="espace:PascalToCamel(Schema/@TableName)" />Delete.ExecuteNonQuery();
		}

		public <xsl:if test="Schema/@IsStatic='True'">static </xsl:if><xsl:value-of select="Schema/@TableName" /> Get<xsl:value-of select="Schema/@TableName" />(<xsl:for-each select="Schema/Columns[IsPK='1']"><xsl:value-of select="concat(LanguageType,' ',espace:PascalToCamel(ColumnName))" /><xsl:if test="position()!=last()">,</xsl:if></xsl:for-each>)
		{
			_<xsl:value-of select="Schema/@TableName" />SelectByPk <xsl:value-of select="espace:PascalToCamel(Schema/@TableName)" />SelectByPk = new _<xsl:value-of select="Schema/@TableName" />SelectByPk();
			<xsl:value-of select="concat(Schema/@TableName, ' ', espace:PascalToCamel(Schema/@TableName))" /> = new <xsl:value-of select="Schema/@TableName" />();
			<xsl:for-each select="Schema/Columns[IsPK='1']">
			<xsl:value-of select="espace:PascalToCamel(/Schema/@TableName)" />SelectByPk.<xsl:value-of select="ColumnName" /> = <xsl:value-of select="espace:PascalToCamel(ColumnName)" />;
			</xsl:for-each>
			<xsl:value-of select="espace:PascalToCamel(Schema/@TableName)" />.SetMetaDataTable(<xsl:value-of select="espace:PascalToCamel(Schema/@TableName)" />SelectByPk.ExecuteDataTable());
			return <xsl:value-of select="espace:PascalToCamel(Schema/@TableName)" />;
		}
</xsl:if>
<xsl:for-each select="Schema/ForeignKeys/ForeignKey">
		public <xsl:if test="/Schema/@IsStatic='True'">static </xsl:if>DataTable Get<xsl:value-of select="/Schema/@TableName" />By<xsl:for-each select="Column"><xsl:value-of select="FKCOLUMN_NAME" /><xsl:if test="position()!=last()">AND</xsl:if></xsl:for-each>(<xsl:for-each select="Column"><xsl:value-of select="concat(SystemTypeName,' ',FKCOLUMN_NAME)" /><xsl:if test="position()!=last()">,</xsl:if></xsl:for-each>)
		{
			_<xsl:value-of select="/Schema/@TableName" />SelectBy<xsl:for-each select="Column"><xsl:value-of select="FKCOLUMN_NAME" /><xsl:if test="position()!=last()">AND</xsl:if></xsl:for-each><xsl:value-of select="concat(' ',espace:PascalToCamel(/Schema/@TableName))" />SelectByFk = new _<xsl:value-of select="/Schema/@TableName" />SelectBy<xsl:for-each select="Column"><xsl:value-of select="FKCOLUMN_NAME" /><xsl:if test="position()!=last()">AND</xsl:if></xsl:for-each>();
			<xsl:for-each select="Column">
			<xsl:value-of select="espace:PascalToCamel(/Schema/@TableName)" />SelectByFk.<xsl:value-of select="FKCOLUMN_NAME" /> = <xsl:value-of select="FKCOLUMN_NAME" />;
			</xsl:for-each>
			return <xsl:value-of select="espace:PascalToCamel(/Schema/@TableName)" />SelectByFk.ExecuteDataTable();
	}
</xsl:for-each>	
  //public <xsl:if test="Schema/@IsStatic='True'">static </xsl:if>DataTable Get<xsl:value-of select="Schema/@TableName" />ByConditions(String keyWord,
  //int pageSize, ref int pageIndex, out int totalPage, out int totalRecord, string sort)
  //{
  //<xsl:value-of select="Schema/@TableName" />SelectByConditions <xsl:value-of select="espace:PascalToCamel(Schema/@TableName)" />SelectByConditions = new <xsl:value-of select="Schema/@TableName" />SelectByConditions();
  //<xsl:value-of select="espace:PascalToCamel(Schema/@TableName)" />SelectByConditions.Keyword = keyword;
  //<xsl:value-of select="espace:PascalToCamel(Schema/@TableName)" />SelectByConditions.SortBy = sort;
  //<xsl:value-of select="espace:PascalToCamel(Schema/@TableName)" />SelectByConditions.CurrentPage = pageIndex;
  //<xsl:value-of select="espace:PascalToCamel(Schema/@TableName)" />SelectByConditions.PageSize = pageSize;
  //DataTable table = <xsl:value-of select="espace:PascalToCamel(Schema/@TableName)" />SelectByConditions.ExecuteDataTable();
  //pageIndex = <xsl:value-of select="espace:PascalToCamel(Schema/@TableName)" />SelectByConditions.CurrentPage;
  //totalPage = <xsl:value-of select="espace:PascalToCamel(Schema/@TableName)" />SelectByConditions.TotalPage;
  //totalRecord = <xsl:value-of select="espace:PascalToCamel(Schema/@TableName)" />SelectByConditions.TotalRecord;
  //return table;
  //}
  }

}</xsl:template>
</xsl:stylesheet>